cssprovider: Cache if rulesets have inheritable style properties
authorBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 03:47:18 +0000 (05:47 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 20:17:58 +0000 (22:17 +0200)
This provides a huge speedup as we only need to preprocess style
properties when they are indeed inherited. This roughly doubles the
performance of the CSS matcher and brings the time taken by
gtk_css_provider_get_style() from 19% to 7% in my favorite benchmark.

gtk/gtkcssprovider.c

index 8dcb09afaad0a52a903c5b2918d8079449d8a060..8659247503dca858f28ee3dbbbe25c1d22d90a01 100644 (file)
@@ -745,6 +745,8 @@ struct GtkCssRuleset
   GtkCssSelector *selector;
   GHashTable *widget_style;
   GHashTable *style;
+
+  guint has_inherit :1;
 };
 
 struct _GtkCssScanner
@@ -970,6 +972,7 @@ gtk_css_ruleset_add (GtkCssRuleset *ruleset,
                                             NULL,
                                             (GDestroyNotify) property_value_free);
 
+  ruleset->has_inherit |= gtk_style_param_get_inherit (pspec);
   g_hash_table_insert (ruleset->style, pspec, value);
 }
 
@@ -1158,7 +1161,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
           if (ruleset->style == NULL)
             continue;
 
-          if (l < length && _gtk_css_selector_get_state_flags (ruleset->selector))
+          if (l < length && (!ruleset->has_inherit || _gtk_css_selector_get_state_flags (ruleset->selector)))
             continue;
 
           if (!gtk_css_ruleset_matches (ruleset, path, l))